# 1、读取分数的数据
with open(file="../../data/score.txt", encoding="utf-8", mode="r") as f:
    lines = f.readlines()
# 2、统计学生的总分
sum_score = {}
for line in lines:
    # 去掉后面的换行符，按照逗号切分
    split = line.strip().split(",")
    # 学号
    id = split[0]
    # 分数
    score = int(split[-1])
    # 累加计算总分
    # 如果学号在字典中存在，累计分数，如果不存在存入当前分数
    if id in sum_score:
        sum_score[id] += score
    else:
        sum_score[id] = score

print(sum_score)

# 读取学生信息
with open(file="../../data/student.txt", encoding="utf-8", mode="r") as f:
    lines = f.readlines()

# 将学生信息保存到字典中，学号作为key，姓名作为value
# 字典：可以通过key快速获取value
students = {}
# 整理学生信息，取出学号和姓名
for index, student in enumerate(lines):
    split = student.split(",")
    id = split[0]
    name = split[1]
    # 将学号和姓名组合成元组保存到列表中
    # students.append((id, name))
    students[id] = name

print(students)

# 效率低下的写法
# for id, score in sum_score.items():
#     for s_id, name in students:
#         if id == s_id:
#             #print(id,s_id,name,score)


for id, score in sum_score.items():
    # 通过学生从学生信息的字典中获取姓名
    name = students[id]
    print(id,name,score)
